package com.itboye.textileexpres.main;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.PopupWindow;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.tbshopcar.listener.OnShoppingCartChangeListener;
import com.itboye.tbshopcar.listener.ShoppingCartBiz;
import com.itboye.textileexpes.beans.ShopCartModel;
import com.itboye.textileexpes.presenter.AppUpdatePresenter;
import com.itboye.textileexpes.presenter.ShopCartPresenter;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.base.BaseFragment;
import com.itboye.textileexpres.base.ResultEntity;
import com.itboye.textileexpres.base.SpPublicParams;
import com.itboye.textileexpres.login.LoginActivity;
import com.itboye.textileexpres.myset.ActivityCustomerService;
import com.itboye.textileexpres.shopcart.ActivityShopCarOrder;
import com.itboye.textileexpres.shopcart.ShopcartExpandableListViewAdapter.CheckInterface;
import com.itboye.textileexpres.shopcart.ShopcartExpandableListViewAdapter.ModifyCountInterface;
import com.itboye.textileexpres.top.GoodsDetail;
import com.itboye.textileexpres.util.IsMobileNumPhone;
import com.itboye.textileexpres.util.PriceChange;
import com.itboye.textileexpres.util.SPUtils;
import com.itboye.textileexpres.util.UIAlertViewDo;
import com.itboye.textileexpres.util.XImageLoader;
import com.itboye.textileexptes.config.GlobalConfig;
/**
 * 购物车
 */
public class ShopCart extends BaseFragment implements Observer {
	AppAdapter mAdapter;
	ShopCartModel cartModel = new ShopCartModel();
	ShopCartPresenter presenter;
	private List<ShopCartModel> goodsList = new ArrayList<ShopCartModel>();
	private String uid;
	ExpandableListView exListView;
	TextView tvtextNumber;
	ImageView all_img;
	ImageView edit_all;
	RelativeLayout count_rel;
	RelativeLayout bottom;
	RelativeLayout no_data;
	boolean isAllEditing = false;
	TextView title;
	ImageView back, img_other;
	TextView tv_total_price;
	TextView to_pay;
	UIAlertViewDo deldialog;
	int count = 0;
	PopupWindow popupWindow;
	int changeNum;
	ArrayList<TextView> arrayList = new ArrayList<>();
	AppUpdatePresenter appUpdatePresenter;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.fragment_shopcar;
	}

	@Override
	public void onMyActivityCreated() {
		// TODO Auto-generated method stub
		presenter = new ShopCartPresenter(this);
		appUpdatePresenter=new AppUpdatePresenter(this);
		uid = (String) SPUtils.get(getActivity(), null, SpPublicParams.UID, "");
		System.out.println("deletedelete"+uid);
		cartModel.setUid(uid);
		title.setText(R.string.shopcar);
		back.setVisibility(View.GONE);
		IntentFilter filter = new IntentFilter("updateshopcar");
		IntentFilter exitfilter = new IntentFilter("newshead");
		IntentFilter loginfilter = new IntentFilter("LoginSuccess");
		getActivity().registerReceiver(broadcastReceiver, filter);
		getActivity().registerReceiver(broadcastReceiver, loginfilter);
		getActivity().registerReceiver(exitReceiver, exitfilter);
		img_other.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if ("".equals(IsMobileNumPhone.isUid())
						|| IsMobileNumPhone.isUid() == null) {
					Intent intent = new Intent(getActivity(),
							LoginActivity.class);
					startActivity(intent);
				} else {
					Intent intent = new Intent(getActivity(),
							ActivityCustomerService.class);
					startActivity(intent);
				}
			}
		});
		if ("".equals(uid) || uid == "") {
			viewGone();
		} else {
			viewVisiable();
			presenter.getInfo(cartModel);

		}
	}

	BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			cartModel.setUid((String) SPUtils.get(getActivity(), null,
					SpPublicParams.UID, "") + "");
			presenter.getInfo(cartModel);
		}
	};
	BroadcastReceiver exitReceiver = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			viewGone();

		}
	};

	private void viewGone() {
		exListView.setVisibility(View.GONE);
		count_rel.setVisibility(View.GONE);
		bottom.setVisibility(View.GONE);
		no_data.setVisibility(View.VISIBLE);
	}

	private void viewVisiable() {
		exListView.setVisibility(View.VISIBLE);
		count_rel.setVisibility(View.VISIBLE);
		bottom.setVisibility(View.VISIBLE);
		no_data.setVisibility(View.GONE);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == ShopCartPresenter.QueryShopCartSuccessEvent) {
				goodsList.clear();
				goodsList.addAll((List<ShopCartModel>) entity.getData());
				exListView = (ExpandableListView) getActivity().findViewById(
						R.id.exListView);
				if (goodsList.size() == 0) {
					viewGone();
				} else {
					viewVisiable();
					mAdapter = new AppAdapter(getActivity());
					mAdapter.setList(goodsList);
					exListView.setAdapter(mAdapter);
					mAdapter.setOnShoppingCartChangeListener(new OnShoppingCartChangeListener() {

						@Override
						public void onSelectItem(boolean isSelectedAll) {
							// TODO Auto-generated method stub
							ShoppingCartBiz.checkItem(isSelectedAll, all_img);
						}

						@Override
						public void onDataChange(String selectCount,
								String selectMoney) {
							// TODO Auto-generated method stub
							tv_total_price.setText(PriceChange
									.Change(selectMoney));
						}
					});
					count = 0;
					for (int i = 0; i < mAdapter.getGroupCount(); i++) {
						exListView.expandGroup(i);
						for (int j = 0; j < goodsList.get(i).getItems().size(); j++) {
							count++;
						}
					}
					tvtextNumber.setText("" + count);

					OnClickListener clickListener = mAdapter.getListener();
					if (clickListener != null) {
						all_img.setOnClickListener(mAdapter.getListener());
						edit_all.setOnClickListener(mAdapter.getListener());
					}
					exListView
							.setOnGroupClickListener(new OnGroupClickListener() {

								@Override
								public boolean onGroupClick(
										ExpandableListView parent, View v,
										int groupPosition, long id) {
									// TODO Auto-generated method stub
									return true;
								}
							});
					exListView
							.setOnChildClickListener(new OnChildClickListener() {

								@Override
								public boolean onChildClick(
										ExpandableListView parent, View v,
										int groupPosition, int childPosition,
										long id) {
									// TODO Auto-generated method stub
									Intent intent = new Intent(getActivity(),
											GoodsDetail.class);
									intent.putExtra(
											"pid",
											goodsList.get(groupPosition)
													.getItems()
													.get(childPosition)
													.getP_id());
									startActivity(intent);
									return false;
								}
							});
					to_pay.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							Intent intent = new Intent(getActivity(),
									ActivityShopCarOrder.class);
							if (ShoppingCartBiz.getShopCart(goodsList)
									.getInfo() == null
									|| ShoppingCartBiz.getShopCart(goodsList)
											.getInfo().size() == 0) {
								toast(getString( R.string.h104));
								return;
							} else {
								intent.putExtra("selected",
										ShoppingCartBiz.getShopCart(goodsList));
								intent.putExtra("totalPrice",
										tv_total_price.getText() + "");
								startActivity(intent);
							}

						}
					});
				}

			} else if (entity.getEventType() == ShopCartPresenter.QueryShopCartFailureEvent) {

			} else if (entity.getEventType() == ShopCartPresenter.DeleteShopCartSuccessEvent) {
				toast(getString(R.string.h1209));//删除成功
				goodsList.clear();
				presenter.getInfo(cartModel);
				mAdapter.notifyDataSetChanged();

			} else if (entity.getEventType() == ShopCartPresenter.DeleteShopCartFailureEvent) {

			} else if (entity.getEventType() == ShopCartPresenter.UpdateShopCartSuccessEvent) {
//				toast(entity.getData() + "ca");
				// goodsList.clear();
				presenter.getInfo(cartModel);
				mAdapter.notifyDataSetChanged();

			} else if (entity.getEventType() == ShopCartPresenter.UpdateShopCartFailureEvent) {

			}
			if (entity.getEventType() == ShopCartPresenter.MoreUpSuccessEvent) {
//				toast(entity.getMsg() + "mo");

			} else if (entity.getEventType() == ShopCartPresenter.MoreUpFailureEvent) {
				toast(entity.getMsg() + "");
				cartModel.setUid((String) SPUtils.get(getActivity(), null,
						SpPublicParams.UID, "") + "");
				presenter.getInfo(cartModel);
			}
			try {
				closeProgressDialog();
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
	}

	class AppAdapter extends BaseExpandableListAdapter {
		CheckInterface checkInterface;
		ModifyCountInterface modifyCountInterface;
		Context context;
		List<ShopCartModel> goodsList;
		boolean isSelectAll = false;
		OnShoppingCartChangeListener mChangeListener;

		public AppAdapter(Context context, List<ShopCartModel> goodsList) {
			// TODO Auto-generated constructor stub
			this.context = context;
			this.goodsList = goodsList;
		}

		public AppAdapter(Context context) {
			// TODO Auto-generated constructor stub
			this.context = context;
		}

		public void setOnShoppingCartChangeListener(
				OnShoppingCartChangeListener changeListener) {
			this.mChangeListener = changeListener;
		}

		public void setList(List<ShopCartModel> goodsList) {
			this.goodsList = goodsList;
			setSettleInfo();
		}

		private void setSettleInfo() {
			// TODO Auto-generated method stub
			String[] infos = ShoppingCartBiz.getShoppingCount(goodsList);
			// 删除或者选择商品之后，需要通知结算按钮，更新自己的数据；
			if (mChangeListener != null && infos != null) {
				mChangeListener.onDataChange(infos[0], infos[1]);
			}
		}

		public OnClickListener getListener() {
			return listener;
		}

		@Override
		public Object getChild(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return goodsList.get(groupPosition).getItems().get(childPosition);
		}

		@Override
		public long getChildId(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return childPosition;
		}

		@Override
		public int getChildrenCount(int groupPosition) {
			// TODO Auto-generated method stub
			return goodsList.get(groupPosition).getItems().size();
		}

		@Override
		public Object getGroup(int groupPosition) {
			// TODO Auto-generated method stub
			return goodsList;
		}

		@Override
		public int getGroupCount() {
			// TODO Auto-generated method stub
			return goodsList.size();
		}

		@Override
		public long getGroupId(int groupPosition) {
			// TODO Auto-generated method stub
			return groupPosition;
		}

		@Override
		public boolean hasStableIds() {
			// TODO Auto-generated method stub
			return true;
		}

		View.OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch (v.getId()) {
				case R.id.all_img:
					isSelectAll = ShoppingCartBiz.selectAll(goodsList,
							isSelectAll, (ImageView) v);
					selectAll();
					setSettleInfo();
					notifyDataSetChanged();
					break;
				case R.id.edit_all:
					arrayList.clear();
					isAllEditing = !isAllEditing;
					if (isAllEditing) {
						edit_all.setImageResource(R.drawable.colloct_save);
					} else {
						showProgressDialog(getString(R.string.h88), true);
						ShopCartModel model = new ShopCartModel();
						model.setUid(IsMobileNumPhone.isUid());
						StringBuffer ids = new StringBuffer();
						StringBuffer counts = new StringBuffer();
						for (int i = 0; i < goodsList.size(); i++) {
							for (int j = 0; j < goodsList.get(i).getItems()
									.size(); j++) {

								ids.append(","
										+ goodsList.get(i).getItems().get(j)
												.getId());
								counts.append(","
										+ goodsList.get(i).getItems().get(j)
												.getCount() + "");
							}
						}
						model.setId(ids.substring(1, ids.length()));
						model.setCount(counts.substring(1, counts.length()));
						Log.e("hushopall",
								ids.substring(1, ids.length()) + "=ids,"
										+ counts.substring(1, counts.length())
										+ ",counts");
						presenter.MoreUp(model);
						edit_all.setImageResource(R.drawable.collect_edit);
					}
					for (int i = 0; i < goodsList.size(); i++) {
						goodsList.get(i).setAllEdit(isAllEditing);
						goodsList.get(i).setGroupEdit(false);
						for (int j = 0; j < goodsList.get(i).getItems().size(); j++) {
							goodsList.get(i).getItems().get(j)
									.setGroupEdit(false);
							goodsList.get(i).getItems().get(j)
									.setAllEdit(isAllEditing);
						}

					}
					notifyDataSetChanged();
					break;
				case R.id.group_edit:
					arrayList.clear();
					int groupPosition3 = Integer.parseInt(String.valueOf(v
							.getTag()));
					isSelectAll = ShoppingCartBiz.selectGroup(goodsList,
							groupPosition3);
					boolean isGroupEditing = !(goodsList.get((int) v.getTag())
							.isGroupEdit());
					goodsList.get(groupPosition3).setGroupEdit(isGroupEditing);
					for (int i = 0; i < goodsList.get(groupPosition3)
							.getItems().size(); i++) {
						goodsList.get(groupPosition3).getItems().get(i)
								.setGroupEdit(isGroupEditing);

					}
					if (isGroupEditing) {

					} else {
						showProgressDialog(getString(R.string.h88), true);
						ShopCartModel model = new ShopCartModel();
						model.setUid(IsMobileNumPhone.isUid());
						StringBuffer ids = new StringBuffer();
						StringBuffer counts = new StringBuffer();
						for (int j = 0; j < goodsList.get(groupPosition3)
								.getItems().size(); j++) {
							ids.append(","
									+ goodsList.get(groupPosition3).getItems()
											.get(j).getId());
							counts.append(","
									+ goodsList.get(groupPosition3).getItems()
											.get(j).getCount() + "");

						}
						Log.e("hushopgroup",
								ids.substring(1, ids.length()) + "=ids,"
										+ counts.substring(1, counts.length())
										+ ",counts");
						model.setId(ids.substring(1, ids.length()));
						model.setCount(counts.substring(1, counts.length()));
						presenter.MoreUp(model);
					}
					for (int i = 0; i < goodsList.size(); i++) {
						goodsList.get(i).setAllEdit(false);
					}
					notifyDataSetChanged();
					break;
				case R.id.check_box_img:
					String tag = String.valueOf(v.getTag());
					if (tag.contains(",")) {
						String s[] = tag.split(",");
						int groupPosition = Integer.parseInt(s[0]);
						int childPosition = Integer.parseInt(s[1]);
						isSelectAll = ShoppingCartBiz.selectOne(goodsList,
								groupPosition, childPosition);
						selectAll();
						setSettleInfo();
						notifyDataSetChanged();
					}
					break;
				case R.id.jian:
					try {
						String jian = String.valueOf(v.getTag());
						if (jian.contains(",")) {
							String s[] = jian.split(",");
							int jiagroupPosition = Integer.parseInt(s[0]);
							int jiachildPosition = Integer.parseInt(s[1]);
							int c = Integer.parseInt(goodsList
									.get(jiagroupPosition).getItems()
									.get(jiachildPosition).getCount());
							if (c > 1) {
								c--;
							}
							goodsList.get(jiagroupPosition).getItems()
									.get(jiachildPosition).setCount(c + "");
							notifyDataSetChanged();
						}
					} catch (NumberFormatException e) {
					}
					break;
				case R.id.jia:
					try {
						String jia = String.valueOf(v.getTag());
						if (jia.contains(",")) {
							String s[] = jia.split(",");
							int jiagroupPosition = Integer.parseInt(s[0]);
							int jiachildPosition = Integer.parseInt(s[1]);
							int c = Integer.parseInt(goodsList
									.get(jiagroupPosition).getItems()
									.get(jiachildPosition).getCount());
							if (c > 0) {
								c++;
							}
							goodsList.get(jiagroupPosition).getItems()
									.get(jiachildPosition).setCount(c + "");
							notifyDataSetChanged();
							// ShopCartModel model = new ShopCartModel();
							// model.setUid(uid);
							// model.setId(goodsList.get(jiagroupPosition)
							// .getItems().get(jiachildPosition).getId());
							// model.setCount(c + "");
							// presenter.update(model);
						}
					} catch (NumberFormatException e) {
					}
					break;
				case R.id.type3_jian:
					try {
						String jian = String.valueOf(v.getTag());
						if (jian.contains(",")) {
							String s[] = jian.split(",");
							int jiagroupPosition = Integer.parseInt(s[0]);
							int jiachildPosition = Integer.parseInt(s[1]);
							int c = Integer.parseInt(goodsList
									.get(jiagroupPosition).getItems()
									.get(jiachildPosition).getCount());
							if (c > 1) {
								c--;
							}
							goodsList.get(jiagroupPosition).getItems()
									.get(jiachildPosition).setCount(c + "");
							notifyDataSetChanged();
							// ShopCartModel model = new ShopCartModel();
							// model.setUid(uid);
							// model.setId(goodsList.get(jiagroupPosition)
							// .getItems().get(jiachildPosition).getId());
							// model.setCount(c + "");
							// presenter.update(model);
						}
					} catch (NumberFormatException e) {
					}
					break;
				case R.id.type3_jia:
					try {
						String jia = String.valueOf(v.getTag());
						if (jia.contains(",")) {
							String s[] = jia.split(",");
							int jiagroupPosition = Integer.parseInt(s[0]);
							int jiachildPosition = Integer.parseInt(s[1]);
							int c = Integer.parseInt(goodsList
									.get(jiagroupPosition).getItems()
									.get(jiachildPosition).getCount());
							if (c > 0) {
								c++;
							}
							goodsList.get(jiagroupPosition).getItems()
									.get(jiachildPosition).setCount(c + "");
							notifyDataSetChanged();
							// ShopCartModel model = new ShopCartModel();
							// model.setUid(uid);
							// model.setId(goodsList.get(jiagroupPosition)
							// .getItems().get(jiachildPosition).getId());
							// model.setCount(c + "");
							// presenter.update(model);
						}
					} catch (NumberFormatException e) {

					}
					break;
				case R.id.delete:
					final String delete = String.valueOf(v.getTag());
					deldialog = new UIAlertViewDo(context, "", R.string.delete
							, R.string.no , R.string.yes );
					deldialog.show();
					deldialog.setClicklistener(new UIAlertViewDo.ClickListenerInterface() {

						@Override
						public void doRight() {
							// TODO Auto-generated method stub
							if (delete.contains(",")) {
								String s[] = delete.split(",");
								int groupPosition = Integer.parseInt(s[0]);
								int childPosition = Integer.parseInt(s[1]);
								ShopCartModel model = new ShopCartModel();
								model.setUid(uid);
								model.setId(goodsList.get(groupPosition)
										.getItems().get(childPosition).getId());
								presenter.delete(model);
							}
							setSettleInfo();
							deldialog.dismiss();
						}

						@Override
						public void doLeft() {
							// TODO Auto-generated method stub
							deldialog.dismiss();
						}
					});

					break;

				default:
					break;
				}
			}
		};

		private void selectAll() {
			if (mChangeListener != null) {
				mChangeListener.onSelectItem(isSelectAll);
			}
		}

		@Override
		public View getGroupView(int groupPosition, boolean isExpanded,
				View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			GroupViewHolder groupViewHolder = null;
			if (convertView == null) {
				groupViewHolder = new GroupViewHolder();
				convertView = LayoutInflater.from(context).inflate(
						R.layout.shopcart_group, null);
				groupViewHolder.publish_name = (TextView) convertView
						.findViewById(R.id.publish_name);
				groupViewHolder.publish_area = (TextView) convertView
						.findViewById(R.id.publish_area);
				groupViewHolder.edit = (ImageView) convertView
						.findViewById(R.id.group_edit);
				convertView.setTag(groupViewHolder);
			} else {
				groupViewHolder = (GroupViewHolder) convertView.getTag();
			}
			ShoppingCartBiz.checkItem(goodsList.get(groupPosition)
					.isGroupSelected(), groupViewHolder.edit);
			boolean isGroupEditing = goodsList.get(groupPosition).isGroupEdit();
			boolean isAllEditing = goodsList.get(groupPosition).isAllEdit();
			if (isAllEditing) {
				groupViewHolder.edit.setVisibility(View.GONE);
			} else {
				groupViewHolder.edit.setVisibility(View.VISIBLE);
			}
			if (isGroupEditing) {
				groupViewHolder.edit.setImageResource(R.drawable.colloct_save);
			} else {
				groupViewHolder.edit.setImageResource(R.drawable.collect_edit);
			}
			groupViewHolder.publish_name.setText(getString(R.string.sender)+ "："
					+ goodsList.get(groupPosition).getPublisher_name());
			groupViewHolder.publish_area.setText((goodsList.get(groupPosition)
					.getPlace_origin()));
			groupViewHolder.edit.setTag(groupPosition);
			groupViewHolder.edit.setOnClickListener(listener);
			return convertView;
		}

		@Override
		public View getChildView(int groupPosition, int childPosition,
				boolean isLastChild, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			ChildViewHolder childViewHolder = null;
			if (convertView == null) {
				childViewHolder = new ChildViewHolder();
				convertView = LayoutInflater.from(context).inflate(
						R.layout.shaopcar_childview, null);
				childViewHolder.check_box_img = (ImageView) convertView
						.findViewById(R.id.check_box_img);
				childViewHolder.tvShixiao=(TextView) convertView.findViewById(R.id.tvShixiao);
				childViewHolder.goods_img = (ImageView) convertView
						.findViewById(R.id.goods_img);
				childViewHolder.goods_name1_tv = (TextView) convertView
						.findViewById(R.id.goods_name1_tv);
				childViewHolder.goods_detail_tv = (TextView) convertView
						.findViewById(R.id.goods_detail_tv);
				childViewHolder.goods_detail_ms = (TextView) convertView
						.findViewById(R.id.goods_detail_ms);
				childViewHolder.color_tv = (TextView) convertView
						.findViewById(R.id.color_tv);
				childViewHolder.price_tv = (TextView) convertView
						.findViewById(R.id.price_tv);
				childViewHolder.price_unit_tv = (TextView) convertView
						.findViewById(R.id.price_unit_tv);
				childViewHolder.num_tv = (TextView) convertView
						.findViewById(R.id.num_tv);
				childViewHolder.delete = (TextView) convertView
						.findViewById(R.id.delete);
				childViewHolder.type3_jian = (TextView) convertView
						.findViewById(R.id.type3_jian);
				childViewHolder.type3_jia = (TextView) convertView
						.findViewById(R.id.type3_jia);
				childViewHolder.input = (TextView) convertView
						.findViewById(R.id.input);
				childViewHolder.type3_input = (TextView) convertView
						.findViewById(R.id.type3_input);
				childViewHolder.jian = (TextView) convertView
						.findViewById(R.id.jian);
				childViewHolder.jia = (TextView) convertView
						.findViewById(R.id.jia);
				childViewHolder.type3_jian = (TextView) convertView
						.findViewById(R.id.type3_jian);
				childViewHolder.type3_jia = (TextView) convertView
						.findViewById(R.id.type3_jia);
				childViewHolder.delete = (TextView) convertView
						.findViewById(R.id.delete);
				childViewHolder.type_1 = (LinearLayout) convertView
						.findViewById(R.id.type_1);
				childViewHolder.type_3 = (LinearLayout) convertView
						.findViewById(R.id.type_3);
				childViewHolder.type_2 = (RelativeLayout) convertView
						.findViewById(R.id.type_2);
				convertView.setTag(childViewHolder);
			} else {
				childViewHolder = (ChildViewHolder) convertView.getTag();
			}
			boolean isChildSelected = goodsList.get(groupPosition).getItems()
					.get(childPosition).isChildSelected();
			boolean isGroupEditing = goodsList.get(groupPosition).getItems()
					.get(childPosition).isGroupEdit();
			boolean AllEditing = goodsList.get(groupPosition).getItems()
					.get(childPosition).isAllEdit();
			childViewHolder.check_box_img.setTag(groupPosition + ","
					+ childPosition);
			childViewHolder.check_box_img.setOnClickListener(listener);
			ShoppingCartBiz.checkItem(isChildSelected,
					childViewHolder.check_box_img);
		
			if (isGroupEditing) {
				childViewHolder.type_2.setVisibility(View.VISIBLE);
				childViewHolder.type_1.setVisibility(View.GONE);
				childViewHolder.type_3.setVisibility(View.GONE);
				childViewHolder.input.setText(goodsList.get(groupPosition)
						.getItems().get(childPosition).getCount());
				childViewHolder.jian
						.setTag(groupPosition + "," + childPosition);
				childViewHolder.jia.setTag(groupPosition + "," + childPosition);
			} else if (AllEditing) {
				childViewHolder.type_2.setVisibility(View.GONE);
				childViewHolder.type_1.setVisibility(View.GONE);
				childViewHolder.type_3.setVisibility(View.VISIBLE);
				childViewHolder.type3_input.setText(goodsList
						.get(groupPosition).getItems().get(childPosition)
						.getCount());
			} else {
				childViewHolder.type_2.setVisibility(View.GONE);
				childViewHolder.type_1.setVisibility(View.VISIBLE);
				childViewHolder.type_3.setVisibility(View.GONE);
			}
			childViewHolder.delete.setTag(groupPosition + "," + childPosition);
			childViewHolder.delete.setOnClickListener(listener);
			XImageLoader.load(
					GlobalConfig.IMAGE_DOUBLE
							+ goodsList.get(groupPosition).getItems()
									.get(childPosition).getIcon_url(),
					childViewHolder.goods_img);
			childViewHolder.goods_name1_tv.setText(goodsList.get(groupPosition)
					.getItems().get(childPosition).getProduct_code());
			childViewHolder.goods_detail_tv
					.setText(goodsList.get(groupPosition).getItems()
							.get(childPosition).getName());
			if ("2".equals(goodsList.get(groupPosition).getItems()
					.get(childPosition).getItem_status())
					|| "4".equals(goodsList.get(groupPosition).getItems()
							.get(childPosition).getItem_status())
					|| "8".equals(goodsList.get(groupPosition).getItems()
							.get(childPosition).getItem_status())
					|| "16".equals(goodsList.get(groupPosition).getItems()
							.get(childPosition).getItem_status())) {
				childViewHolder.goods_detail_ms.setText(goodsList.get(groupPosition)
						.getItems().get(childPosition).getItem_status());
				childViewHolder.check_box_img.setVisibility(View.GONE);
				childViewHolder.tvShixiao.setVisibility(View.VISIBLE);
			} else {
				childViewHolder.goods_detail_ms.setText(goodsList.get(groupPosition)
						.getItems().get(childPosition).getSku_desc());
			}
			
			childViewHolder.price_tv.setText(PriceChange.Change(goodsList
					.get(groupPosition).getItems().get(childPosition)
					.getPrice()));
			childViewHolder.price_unit_tv.setText("/"
					+ goodsList.get(groupPosition).getItems()
							.get(childPosition).getUnit_desc());
			childViewHolder.num_tv.setText("X"
					+ goodsList.get(groupPosition).getItems()
							.get(childPosition).getCount());
			childViewHolder.type3_jian.setTag(groupPosition + ","
					+ childPosition);
			childViewHolder.type3_jia.setTag(groupPosition + ","
					+ childPosition);
			childViewHolder.type3_input.setTag(groupPosition + ","
					+ childPosition);
			childViewHolder.input.setTag(groupPosition + "," + childPosition);
			childViewHolder.type3_input.setOnClickListener(listener);
			childViewHolder.input.setOnClickListener(listener);
			childViewHolder.jia.setOnClickListener(listener);
			childViewHolder.jian.setOnClickListener(listener);
			childViewHolder.type3_jia.setOnClickListener(listener);
			childViewHolder.type3_jian.setOnClickListener(listener);
			return convertView;
		}

		public boolean isChildSelectable(int i, int i1) {
			return false;
		}

		class ChildViewHolder {
			ImageView check_box_img;
			ImageView goods_img;
			TextView goods_name1_tv, goods_detail_tv,goods_detail_ms, color_tv, price_tv,
					price_unit_tv, num_tv, jian, jia, type3_jian, type3_jia,
					delete,tvShixiao;
			TextView input, type3_input;
			LinearLayout type_1, type_3;
			RelativeLayout type_2;
		}

	}

	class GroupViewHolder {
		TextView publish_name, publish_area;
		ImageView edit;
	}

}
